//
//  LPPHallController.m
//  Lottery
//
//  Created by 刘盼 on 16/1/21.
//  Copyright © 2016年 lhheh. All rights reserved.
//

#import "LPPHallController.h"

@interface LPPHallController ()
//遮罩
@property(nonatomic,strong)UIView *coverView;

@property(nonatomic,strong)UIImageView *imageView;

@end

@implementation LPPHallController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImage *image = [UIImage imageNamed:@"CS50_activity_image"];
    //不进行系统默认的渲染
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(activityClick)];
    
    self.navigationItem.leftBarButtonItem = item;
    
}

-(void)activityClick {
  //遮罩
    self.coverView = [[UIView alloc]initWithFrame:self.view.frame];
    
    self.coverView.alpha = 0.5;
    
    self.coverView.backgroundColor = [UIColor blackColor];
    //添加到self.view上不符合现实
    [self.tabBarController.view addSubview:self.coverView];
    //图片
    self.imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"showActivity"]];
    
    self.imageView.center = self.coverView.center;
    //开启用户交互
    self.imageView.userInteractionEnabled = YES;
    //不能添加到coverView上，不然会有一层阴影
    [self.tabBarController.view addSubview:self.imageView];
    //关闭按钮
    UIButton *closeBtn = [[UIButton alloc]init];
    
    [closeBtn setImage:[UIImage imageNamed:@"alphaClose"] forState:UIControlStateNormal];
    
    [closeBtn addTarget:self action:@selector(closeClick) forControlEvents:UIControlEventTouchUpInside];
    
    CGFloat w = closeBtn.imageView.image.size.width;
    CGFloat h = closeBtn.imageView.image.size.height;
    CGFloat x = self.imageView.bounds.size.width - w;
    CGFloat y = 0;
    
    closeBtn.frame = CGRectMake(x, y, w, h);
    
    [self.imageView addSubview:closeBtn];
    
}

-(void)closeClick {
   
    [UIView animateWithDuration:2 animations:^{
        
        self.imageView.alpha = 0;
        
        self.coverView.alpha = 0;
        
    } completion:^(BOOL finished) {
        
        [self.imageView removeFromSuperview];
        
        [self.coverView removeFromSuperview];
    }];
}
@end
